﻿using OddUserManager.Data.IRepositories;
using OddUserManager.Model;
using OddUserManager.Service.IServices;
using System;
using System.Collections.Generic;
using System.Text;

namespace OddUserManager.Service.Services
{
    public class SiteService : ISiteService
    {
        ISiteRepository _repository;

        public SiteService()
        {
        }

        public SiteService(ISiteRepository repository)
        {
            _repository = repository;
        }

        public void DeleteBatch(List<int> ids)
        {
            if (_repository.GetSiteUserCount(ids) > 0)
            {
                throw new Exception("不能删除有用户的站点");
            }

            foreach (var i in ids)
            {
                _repository.Delete(i);
            }

            // _repository.DeleteBatch(ids);
        }

        public Site Get(int id)
        {
            return _repository.Get(id);
        }

        public IEnumerable<Site> GetAllList()
        {
            return _repository.GetAllList();
        }

        public List<Site> GetNoneChildrenSites()
        {
            return _repository.GetNoneChildrenSites();
        }

        public bool UpdateOrInsert(Site entity)
        {
            return _repository.InsertOrUpdate(entity);
        }
    }
}
